package licode.unisop.types.dp;

import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.util.Assert;

/**
 * 封装身份证号码元类型
 *
 * @author WR
 */
public class IdCard {

    private final String id;

    public IdCard(String id) {
        if (StrUtil.isBlank(id)) {
            this.id = "";
        } else {
            if (!IdcardUtil.isValidCard(id)) {
                Assert.isTrue(PhoneUtil.isMobile(id), "身份证号码错误：" + id);
            }
            this.id = id;
        }
    }

    public String getId() {
        return id;
    }

    @Override
    public String toString() {
        return id;
    }
}
